"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global globalRootUrl,globalTranslate,Form */
var loginForm = {
  /**
   * jQuery object for the form.
   * @type {jQuery}
   */
  $formObj: $('#login-form'),

  /**
   * The jQuery object for the submit button.
   * @type {jQuery}
   */
  $submitButton: $('#submitbutton'),

  /**
   * The jQuery object for the checkboxes.
   * @type {jQuery}
   */
  $checkBoxes: $('.checkbox'),

  /**
   * Validation rules for the form fields before submission.
   *
   * @type {object}
   */
  validateRules: {
    login: {
      identifier: 'login',
      rules: [{
        type: 'empty',
        prompt: globalTranslate.auth_ValidateLoginNotEmpty
      }]
    },
    password: {
      identifier: 'password',
      rules: [{
        type: 'empty',
        prompt: globalTranslate.auth_ValidatePasswordNotEmpty
      }]
    }
  },

  /**
   * Initializes the login form functionality.
   */
  initialize: function initialize() {
    loginForm.initializeForm();
    $('input').keyup(function (event) {
      if (event.keyCode === 13) {
        loginForm.$submitButton.click();
      }
    }).on('input', function () {
      $('.message.ajax').remove();
    });
    loginForm.$checkBoxes.checkbox();
  },

  /**
   * Callback function to be called before the form is sent
   * @param {Object} settings - The current settings of the form
   * @returns {Object} - The updated settings of the form
   */
  cbBeforeSendForm: function cbBeforeSendForm(settings) {
    var result = settings;
    result.data = loginForm.$formObj.form('get values');
    var backUri = "".concat(location.pathname).concat(location.search);
    result.data.backUri = backUri.replace(globalRootUrl, '');
    return result;
  },

  /**
   * Callback function to be called after the form has been sent.
   * @param {Object} response - The response from the server after the form is sent
   */
  cbAfterSendForm: function cbAfterSendForm(response) {},

  /**
   * Initialize the form with custom settings
   */
  initializeForm: function initializeForm() {
    Form.$formObj = loginForm.$formObj;
    Form.url = "".concat(globalRootUrl, "session/start"); // Form submission URL

    Form.validateRules = loginForm.validateRules; // Form validation rules

    Form.cbBeforeSendForm = loginForm.cbBeforeSendForm; // Callback before form is sent

    Form.cbAfterSendForm = loginForm.cbAfterSendForm; // Callback after form is sent

    Form.keyboardShortcuts = false;
    Form.initialize();
  }
}; // When the document is ready, initialize the login form.

$(document).ready(function () {
  loginForm.initialize();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9TZXNzaW9uL2xvZ2luLWZvcm0uanMiXSwibmFtZXMiOlsibG9naW5Gb3JtIiwiJGZvcm1PYmoiLCIkIiwiJHN1Ym1pdEJ1dHRvbiIsIiRjaGVja0JveGVzIiwidmFsaWRhdGVSdWxlcyIsImxvZ2luIiwiaWRlbnRpZmllciIsInJ1bGVzIiwidHlwZSIsInByb21wdCIsImdsb2JhbFRyYW5zbGF0ZSIsImF1dGhfVmFsaWRhdGVMb2dpbk5vdEVtcHR5IiwicGFzc3dvcmQiLCJhdXRoX1ZhbGlkYXRlUGFzc3dvcmROb3RFbXB0eSIsImluaXRpYWxpemUiLCJpbml0aWFsaXplRm9ybSIsImtleXVwIiwiZXZlbnQiLCJrZXlDb2RlIiwiY2xpY2siLCJvbiIsInJlbW92ZSIsImNoZWNrYm94IiwiY2JCZWZvcmVTZW5kRm9ybSIsInNldHRpbmdzIiwicmVzdWx0IiwiZGF0YSIsImZvcm0iLCJiYWNrVXJpIiwibG9jYXRpb24iLCJwYXRobmFtZSIsInNlYXJjaCIsInJlcGxhY2UiLCJnbG9iYWxSb290VXJsIiwiY2JBZnRlclNlbmRGb3JtIiwicmVzcG9uc2UiLCJGb3JtIiwidXJsIiwia2V5Ym9hcmRTaG9ydGN1dHMiLCJk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KiBAdHlwZSB7alF1ZXJ5fVxuICAgICAqL1xuICAgICRzdWJtaXRCdXR0b246ICQoJyNzdWJtaXRidXR0b24nKSxcblxuICAgIC8qKlxuICAgICAqIFRoZSBqUXVlcnkgb2JqZWN0IGZvciB0aGUgY2hlY2tib3hlcy5cbiAgICAgKiBAdHlwZSB7alF1ZXJ5fVxuICAgICAqL1xuICAgICRjaGVja0JveGVzOiAkKCcuY2hlY2tib3gnKSxcblxuICAgIC8qKlxuICAgICAqIFZhbGlkYXRpb24gcnVsZXMgZm9yIHRoZSBmb3JtIGZpZWxkcyBiZWZvcmUgc3VibWlzc2lvbi5cbiAgICAgKlxuICAgICAqIEB0eXBlIHtvYmplY3R9XG4gICAgICovXG4gICAgdmFsaWRhdGVSdWxlczoge1xuICAgICAgICBsb2dpbjoge1xuICAgICAgICAgICAgaWRlbnRpZmllcjogJ2xvZ2luJyxcbiAgICAgICAgICAgIHJ1bGVzOiBbXG4gICAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiAnZW1wdHknLFxuICAgICAgICAgICAgICAgICAgICBwcm9tcHQ6IGdsb2JhbFRyYW5zbGF0ZS5hdXRoX1ZhbGlkYXRlTG9naW5Ob3RFbXB0eSxcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgXSxcbiAgICAgICAgfSxcbiAgICAgICAgcGFzc3dvcmQ6IHtcbiAgICAgICAgICAgIGlkZW50aWZpZXI6ICdwYXNzd29yZCcsXG4gICAgICAgICAgICBydWxlczogW1xuICAgICAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogJ2VtcHR5JyxcbiAgICAgICAgICAgICAgICAgICAgcHJvbXB0OiBnbG9iYWxUcmFuc2xhdGUuYXV0aF9WYWxpZGF0ZVBhc3N3b3JkTm90RW1wdHksXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIF0sXG4gICAgICAgIH0sXG4gICAgfSxcblxuICAgIC8qKlxuICAgIC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